﻿// Decompiled with JetBrains decompiler
// Type: System.Web.Razor.Text.SourceLocation
// Assembly: System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
// MVID: 682513D6-F37E-48AC-9909-F3EE103CFF14
// Assembly location: D:\Project\Idea\无人机外网\uav\客户端工程\排查工具\bin\Release\System.Web.Razor.dll

using System.Globalization;

namespace System.Web.Razor.Text
{
  /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Represents a source location.</summary>
  [Serializable]
  public struct SourceLocation : IEquatable<SourceLocation>, IComparable<SourceLocation>
  {
    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.</summary>
    public static readonly SourceLocation Undefined = SourceLocation.CreateUndefined();
    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.</summary>
    public static readonly SourceLocation Zero = new SourceLocation(0, 0, 0);
    private int _absoluteIndex;
    private int _lineIndex;
    private int _characterIndex;

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Initializes a new instance of the <see cref="T:System.Web.Razor.Text.SourceLocation" /> class.</summary>
    /// <param name="absoluteIndex">The absolute index.</param>
    /// <param name="lineIndex">The line index.</param>
    /// <param name="characterIndex">The character index.</param>
    public SourceLocation(int absoluteIndex, int lineIndex, int characterIndex)
    {
      this._absoluteIndex = absoluteIndex;
      this._lineIndex = lineIndex;
      this._characterIndex = characterIndex;
    }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Gets the absolute index for the source location.</summary>
    /// <returns>The absolute index for the source location.</returns>
    public int AbsoluteIndex => this._absoluteIndex;

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Gets the line index for the source location.</summary>
    /// <returns>The line index for the source location.</returns>
    public int LineIndex => this._lineIndex;

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Gets the character index for the source location.</summary>
    /// <returns>The character index for the source location.</returns>
    public int CharacterIndex => this._characterIndex;

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Returns a string representation of the source location.</summary>
    /// <returns>A string representation of the source location.</returns>
    public override string ToString() => string.Format((IFormatProvider) CultureInfo.CurrentCulture, "({0}:{1},{2})", (object) this.AbsoluteIndex, (object) this.LineIndex, (object) this.CharacterIndex);

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Determines whether the specified object is equal to the current object.</summary>
    /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns>
    /// <param name="obj">The object to compare to.</param>
    public override bool Equals(object obj) => obj is SourceLocation other && this.Equals(other);

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Returns the hash code for this instance.</summary>
    /// <returns>The hash code for this instance.</returns>
    public override int GetHashCode() => this.AbsoluteIndex;

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Determines whether the current <see cref="T:System.Web.Razor.Text.SourceLocation" /> object is equal to the other <see cref="T:System.Web.Razor.Text.SourceLocation" /> object.</summary>
    /// <returns>true if the current object is equal to the other object; otherwise, false.</returns>
    /// <param name="other">The object to compare to.</param>
    public bool Equals(SourceLocation other) => this.AbsoluteIndex == other.AbsoluteIndex && this.LineIndex == other.LineIndex && this.CharacterIndex == other.CharacterIndex;

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Compares current object to the other object.</summary>
    /// <returns>The value of the objects compared.</returns>
    /// <param name="other">The object to compare.</param>
    public int CompareTo(SourceLocation other) => this.AbsoluteIndex.CompareTo(other.AbsoluteIndex);

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Advances the specified object to the given location.</summary>
    /// <returns>The source location.</returns>
    /// <param name="left">The location where to advance the object.</param>
    /// <param name="text">The text that advances to the given location.</param>
    public static SourceLocation Advance(SourceLocation left, string text)
    {
      SourceLocationTracker sourceLocationTracker = new SourceLocationTracker(left);
      sourceLocationTracker.UpdateLocation(text);
      return sourceLocationTracker.CurrentLocation;
    }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Adds the two <see cref="T:System.Web.Razor.Text.SourceLocation" /> object.</summary>
    /// <returns>The sum of the two <see cref="T:System.Web.Razor.Text.SourceLocation" /> object.</returns>
    /// <param name="left">The first object to add.</param>
    /// <param name="right">The second object to add.</param>
    public static SourceLocation Add(SourceLocation left, SourceLocation right) => right.LineIndex > 0 ? new SourceLocation(left.AbsoluteIndex + right.AbsoluteIndex, left.LineIndex + right.LineIndex, right.CharacterIndex) : new SourceLocation(left.AbsoluteIndex + right.AbsoluteIndex, left.LineIndex + right.LineIndex, left.CharacterIndex + right.CharacterIndex);

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Subtracts the first object to the second object.</summary>
    /// <returns>The difference of the two objects.</returns>
    /// <param name="left">The first object.</param>
    /// <param name="right">The second object.</param>
    public static SourceLocation Subtract(SourceLocation left, SourceLocation right) => new SourceLocation(left.AbsoluteIndex - right.AbsoluteIndex, left.LineIndex - right.LineIndex, left.LineIndex != right.LineIndex ? left.CharacterIndex : left.CharacterIndex - right.CharacterIndex);

    private static SourceLocation CreateUndefined() => new SourceLocation()
    {
      _absoluteIndex = -1,
      _lineIndex = -1,
      _characterIndex = -1
    };

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Determines whether the first object is less than the second object.</summary>
    /// <returns>true if the first object is greater than the second object; otherwise, false.</returns>
    /// <param name="left">The first object.</param>
    /// <param name="right">The second object.</param>
    public static bool operator <(SourceLocation left, SourceLocation right) => left.CompareTo(right) < 0;

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Determines whether the first object is greater than the second object.</summary>
    /// <returns>true if the first object is greater than the second object; otherwise, false.</returns>
    /// <param name="left">The first object.</param>
    /// <param name="right">The second object.</param>
    public static bool operator >(SourceLocation left, SourceLocation right) => left.CompareTo(right) > 0;

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Determines whether the two objects are equal.</summary>
    /// <returns>true if the two objects are equal; otherwise, false.</returns>
    /// <param name="left">The first object to compare.</param>
    /// <param name="right">The second object to compare.</param>
    public static bool operator ==(SourceLocation left, SourceLocation right) => left.Equals(right);

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Determines whether the two <see cref="T:System.Web.Razor.Text.SourceLocation" />object are not equal.</summary>
    /// <returns>true if the two objects are not equal; otherwise, false.</returns>
    /// <param name="left">The object to compare.</param>
    /// <param name="right">The object to compare.</param>
    public static bool operator !=(SourceLocation left, SourceLocation right) => !left.Equals(right);

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Adds the two <see cref="T:System.Web.Razor.Text.SourceLocation" /> object.</summary>
    /// <returns>The <see cref="T:System.Web.Razor.Text.SourceLocation" /> that is the sum of the two object.</returns>
    /// <param name="left">The object to add.</param>
    /// <param name="right">The object to add.</param>
    public static SourceLocation operator +(SourceLocation left, SourceLocation right) => SourceLocation.Add(left, right);

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.</summary>
    /// <returns>Returns <see cref="T:System.Web.Razor.Text.SourceLocation" />.</returns>
    public static SourceLocation operator -(SourceLocation left, SourceLocation right) => SourceLocation.Subtract(left, right);
  }
}
